package com.v3admin.system.controller;

import com.v3admin.common.controller.IResponse;
import com.v3admin.system.domain.SystemRole;
import com.v3admin.system.service.SystemRoleService;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;

/**
 * 角色
 *
 * @author Junpeng.Li
 * @date 2023-12-12 17:33
 */
@RestController
@Validated
@RequestMapping(value = "/system/role")
@AllArgsConstructor
public class SystemRoleController {

    private final SystemRoleService systemRoleService;

    /**
     * 获取角色信息
     *
     * @param roleId 角色ID
     * @return 角色信息
     */
    @GetMapping(value = "/info")
    public IResponse roleInfo(@NotEmpty(message = "角色ID不能为空") Long roleId) {
        SystemRole role = systemRoleService.getById(roleId);
        return IResponse.success(role);
    }

    /**
     * 添加一个角色
     *
     * @param role 角色信息
     * @return 添加结果
     */
    @PostMapping
    public IResponse add(@RequestBody @Valid SystemRole role) {
        systemRoleService.save(role);
        return IResponse.success("角色添加成功");
    }

}
